package com.yeyks.controller.platform;

import com.yeyks.account.dal.domain.AccountInfo;
import com.yeyks.common.appcommon.dto.platform.AppCouponBasicDTO;
import com.yeyks.common.appcommon.dto.platform.AppCouponInfoDTO;
import com.yeyks.common.appcommon.dto.account.AppAccountDTO;
import com.yeyks.common.appcommon.param.platform.GetCouponDetailParam;
import com.yeyks.common.appcommon.param.platform.QueryCouponParam;
import com.yeyks.common.appcommon.result.CommonPage;
import com.yeyks.common.appcommon.result.CommonResult;
import com.yeyks.common.utils.apputil.bean.MyBeanUtils;
import com.yeyks.commonReference.service.other.CouponInfoService;
import com.yeyks.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author: gui
 * @date: 2019/5/29 0029 14:53
 */
@Api(tags = "AppCouponController_优惠券接口",description = "优惠券相关的【查询】【详情】")
@RestController
@RequestMapping("/platform/coupon")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AppCouponController extends BaseController {

     private final CouponInfoService couponInfoService;

     @ApiOperation("分页查询所有优惠券")
     @PostMapping("/list")
     public CommonResult<CommonPage<AppCouponBasicDTO>> list(@Valid QueryCouponParam param){

          AppAccountDTO appAccountDTO = validToken(param.getToken(), param.getVersion(), param.getPlatform());

          return couponInfoService.selectPageByParam(param, MyBeanUtils.convert(appAccountDTO, AccountInfo.class));
          //return couponService.list(param);
     }

     @ApiOperation("查询优惠券的详情")
     @PostMapping("/get")
     public CommonResult<AppCouponInfoDTO> getCouponDetail(@Valid GetCouponDetailParam getCouponDetailParam){

          AppAccountDTO appAccountDTO = validToken(getCouponDetailParam.getToken(),
                  getCouponDetailParam.getVersion(), getCouponDetailParam.getPlatform());

          return couponInfoService.getCouponDetail(getCouponDetailParam, MyBeanUtils.convert(appAccountDTO, AccountInfo.class));
          //return couponService.getCouponDetail(token, id, version, platform);
     }

}
